package com.sayice.robotconflict.game.msg.data.send;

import cn.hutool.core.bean.BeanUtil;
import com.sayice.robotconflict.entity.SocialPlayerEntity;
import com.sayice.robotconflict.game.Game;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 好友信息
 *
 * @author shubing
 */
@Getter
@Setter
@ToString
public class FriendInfo implements Serializable {
    private static final long serialVersionUID = 1L;
    
    /**
     * 玩家ID
     */
    private String id;
    
    /**
     * 玩家名
     */
    private String name;
    
    /**
     * 是否在线
     */
    private boolean online;
    
    public static FriendInfo of(SocialPlayerEntity socialPlayerEntity) {
        FriendInfo friendInfo = BeanUtil.copyProperties(socialPlayerEntity, FriendInfo.class);
        friendInfo.setOnline(Game.PLAYER_GROUP.find(friendInfo.getId()) != null);
        return friendInfo;
    }
    
    public static List<FriendInfo> listOf(List<SocialPlayerEntity> socialPlayerEntities) {
        return socialPlayerEntities.stream().map(entity -> {
            FriendInfo friendInfo = BeanUtil.copyProperties(entity, FriendInfo.class);
            friendInfo.setOnline(Game.PLAYER_GROUP.find(friendInfo.getId()) != null);
            return friendInfo;
        }).collect(Collectors.toList());
    }
}
